<template>
  <div id="app">
    <el-form  :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="时间范围" required >
          <el-form-item prop="date1" style="width:200px">
            <el-date-picker type="date" placeholder="开始时间" v-model="ruleForm.start_date" style="width: 100%;"></el-date-picker>
          </el-form-item>
          <el-form-item prop="date2" style="width:200px">
            <el-date-picker placeholder="结束时间" v-model="ruleForm.end_date" style="width: 100%;"></el-date-picker>
          </el-form-item>
      </el-form-item>

      <el-form-item label="提交地址" required style="width:400px">
          <el-input type="text" placeholder="url" v-model="ruleForm.url" style="width: 100%;"></el-input>
      </el-form-item>
      <el-form-item style="float: left">
        <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import Cookies from 'js-cookie'
  import {send} from ".././api/submitdate";
  export default {
    data() {
      return {
        ruleForm: {
          start_date: '',
          end_date: '',
          url:`http://10.202.156.38/sword2.0/job/zhyjzt/save`,
          cok:'',
        },
        rules: {
          start_date: [
            { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
          ],
          end_date: [
            { type: 'date', required: true, message: '请选择时间', trigger: 'change' }
          ]
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            send(this.form).then(res => {
              console.log('提交成功');
              console.log('res');
              console.log(res);
              Cookies.set('xx', this.resetForm.cok, { expires: 1 })
            }).catch(err => {
              console.log('提交no成功');
              console.log('err.response.data.message');
              console.log(err.response.data.message)
            })
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>

<style>
  #app {
    font-family: Avenir, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    margin-top: 60px;
  }
</style>
